package com.dinadi.yidi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.dinadi.yidi.R;
import com.dinadi.yidi.bean.ExhibitionreaRequestEntity;
import com.dinadi.yidi.bean.MessageRequestEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * author: JiaYu.He
 * Date: 2017/3/21
 * Time: 12:47
 */

public class MessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<MessageRequestEntity> mDatas = new ArrayList<>();


    public void addAllData(List<MessageRequestEntity> dataList) {
        this.mDatas.addAll(dataList);
        notifyDataSetChanged();
    }

    public void clearData() {
        this.mDatas.clear();
    }

    public MessageAdapter(Context context) {
        mContext = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_message_item, parent, false);
        return new MessageAdapter.ItemViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {


        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
//            String         str            = mDatas.get(position);
        itemViewHolder.text_msg.setText(mDatas.get(position).getTitle());
        itemViewHolder.text_content.setText(mDatas.get(position).getContent());


    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }


    public class ItemViewHolder extends RecyclerView.ViewHolder {

        TextView text_msg, text_content;
        ImageView imageView;

        public ItemViewHolder(View itemView) {
            super(itemView);
            text_msg = (TextView) itemView.findViewById(R.id.text_msg);
            text_content = (TextView) itemView.findViewById(R.id.text_content);
            imageView = (ImageView) itemView.findViewById(R.id.img_msg);
          //  initListener(itemView);
        }

        private void initListener(View itemView) {
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(mContext, "poistion " + getAdapterPosition(), Toast.LENGTH_SHORT).show();
                }
            });
        }
    }


}

